<?php
class LinksAction extends AdminAction{
	protected function db(){
		$links=M('Links');
		return $links;
	}

	//友情链接列表
	public function index(){
		$links=$this->db();
		$list=$links->select();

		$i=0;
		foreach($list as $k=>$v){
			if($v['status']=='2' || !$v['status']){
				$list[$i]['statustext']='未审核';
			}
			if($v['status']=='1'){
				$list[$i]['statustext']='已审核';
			}	
			$i++;
		}

		$this->assign('list',$list);
		$this->display();
	}
	//添加友情链接
	public function addlink(){
		$this->display();
	}
	public function add(){
		$links=$this->db();

		$result=$links->add($_POST);
		if($result){
			$this->success('添加成功','index');
		}else{
			$this->error('添加失败');
		}

	}

	//编辑友情链接
	public function editlink(){
		$links=$this->db();
		$list=$links->find($_GET['id']);
		$this->assign('list',$list);
		$this->display();
	}
	public function edit(){
		$links=$this->db();

		$result=$links->where('id='.$_POST['id'])->save($_POST);

		if($result){
			$this->success('编辑成功','index');
		}else{
			$this->error('编辑失败');
		}
	
	}

	//删除友情链接
	public function del(){
		$links=$this->db();
		$result=$links->delete($_GET['id']);
		if($result){
			$this->success('删除成功');
		}else{
			$this->error('删除失败');
		}
	}

	//审核状态
	public function status(){
		$links=$this->db();
		$_GET['status']=$_GET['status']==2?1:2;
		$result=$links->where('id='.$_GET['id'])->save($_GET);
		if($result){
			$this->success('状态切换成功');
		}else{
			$this->error('状态切换失败');
		}
	}
}